package com.fr.chart.core.glyph;

import com.fr.base.core.IteratorChain;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.LineStyleInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.FoldLine;
import com.fr.chart.core.Glyph;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.MarkerGlyph;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class RadarPlotGlyph extends PlotGlyph
{
  private static final long serialVersionUID = 2762582684044348340L;
  public static final String XML_TAG = "RadarPlotGlyph";
  private RadarAxisGlyph radarAxisGlyph;
  private boolean isFilled = false;
  private boolean showLine = true;
  private boolean showMarker = true;

  public void layoutAxisGlyph()
  {
    this.radarAxisGlyph.init(new Rectangle2D.Double(0.0D, 0.0D, getBounds().getWidth(), getBounds().getHeight()));
    this.radarAxisGlyph.calculateAxisLengthUnit();
  }

  public void layoutDataSeriesGlyph()
  {
    for (int i = 0; i < getSeriesSize(); ++i)
    {
      Object localObject;
      DataSeries localDataSeries = getSeries(i);
      GeneralPath localGeneralPath = new GeneralPath();
      for (int j = 0; j < localDataSeries.getDataPointCount(); ++j)
      {
        localObject = localDataSeries.getDataPoint(j);
        double d = ((DataPoint)localObject).getValue();
        Point2D localPoint2D = getRadarAxisGlyph().getPoint2D(j, d);
        if (((DataPoint)localObject).isValueIsNull())
        {
          if (!(isNullValueBreak()))
            break label246:
          localPoint2D = getRadarAxisGlyph().getOrigin();
        }
        if (j == 0)
          localGeneralPath.moveTo((float)localPoint2D.getX(), (float)localPoint2D.getY());
        else
          localGeneralPath.lineTo((float)localPoint2D.getX(), (float)localPoint2D.getY());
        if (isShowMarker())
        {
          MarkerGlyph localMarkerGlyph = new MarkerGlyph();
          ((DataPoint)localObject).setDrawImpl(localMarkerGlyph);
          localMarkerGlyph.setShape(new Rectangle2D.Double(localPoint2D.getX() - 5.0D, localPoint2D.getY() - 5.0D, 10.0D, 10.0D));
          localMarkerGlyph.dealCondition4Line(getSeriesCollection(), i);
        }
        else
        {
          ((DataPoint)localObject).setShape(new Rectangle2D.Double(localPoint2D.getX() - 5.0D, localPoint2D.getY() - 5.0D, 10.0D, 10.0D));
        }
        dealDataPointLabelBounds((DataPoint)localObject, i);
      }
      localGeneralPath.closePath();
      CompositeGlyph localCompositeGlyph = new CompositeGlyph();
      if (isShowLine())
      {
        localObject = new FoldLine(localGeneralPath);
        localCompositeGlyph.add((Glyph)localObject);
        ((FoldLine)localObject).getLineStyleInfo().dealCondition(getSeriesCollection(), i);
      }
      if (isFilled())
      {
        localObject = new ShapeGlyph(localGeneralPath);
        ((ShapeGlyph)localObject).getInfo().dealCondition(getSeriesCollection(), i);
        localCompositeGlyph.add((Glyph)localObject);
      }
      localDataSeries.setDrawImpl(localCompositeGlyph);
    }
    label246:
  }

  public Iterator selectableChildren()
  {
    ArrayList localArrayList = new ArrayList();
    if (this.radarAxisGlyph != null)
      localArrayList.add(this.radarAxisGlyph);
    return new IteratorChain(new Iterator[] { localArrayList.iterator(), super.selectableChildren() });
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if (this.radarAxisGlyph != null)
      this.radarAxisGlyph.draw(localGraphics2D);
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
    super.draw(localGraphics2D);
  }

  public void setRadarAxisGlyph(RadarAxisGlyph paramRadarAxisGlyph)
  {
    this.radarAxisGlyph = paramRadarAxisGlyph;
  }

  public RadarAxisGlyph getRadarAxisGlyph()
  {
    return this.radarAxisGlyph;
  }

  public void setFilled(boolean paramBoolean)
  {
    this.isFilled = paramBoolean;
  }

  public boolean isFilled()
  {
    return this.isFilled;
  }

  public void setShowLine(boolean paramBoolean)
  {
    this.showLine = paramBoolean;
  }

  public boolean isShowLine()
  {
    return this.showLine;
  }

  public void setShowMarker(boolean paramBoolean)
  {
    this.showMarker = paramBoolean;
  }

  public boolean isShowMarker()
  {
    return this.showMarker;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("RadarPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("showMarker", this.showMarker).attr("showLine", this.showLine).attr("fill", this.isFilled).end();
    if (this.radarAxisGlyph != null)
      this.radarAxisGlyph.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("showMarker")) != null)
          this.showMarker = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("showLine")) != null)
          this.showLine = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("fill")) != null)
          this.isFilled = Boolean.valueOf(str2).booleanValue();
      }
      else if (str1.equals("RadarAxisGlyph"))
      {
        this.radarAxisGlyph = ((RadarAxisGlyph)paramXMLableReader.readXMLObject(new RadarAxisGlyph()));
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof RadarPlotGlyph))
      return false;
    RadarPlotGlyph localRadarPlotGlyph = (RadarPlotGlyph)paramObject;
    if (!(super.equals(localRadarPlotGlyph)))
      return false;
    if (localRadarPlotGlyph.showLine != this.showLine)
      return false;
    if (localRadarPlotGlyph.showMarker != this.showMarker)
      return false;
    if (localRadarPlotGlyph.isFilled != this.isFilled)
      return false;
    return (Equals.equals(localRadarPlotGlyph.radarAxisGlyph, this.radarAxisGlyph));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    RadarPlotGlyph localRadarPlotGlyph = (RadarPlotGlyph)super.clone();
    if (this.radarAxisGlyph != null)
      localRadarPlotGlyph.radarAxisGlyph = ((RadarAxisGlyph)this.radarAxisGlyph.clone());
    return localRadarPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.radarAxisGlyph != null)
      localJSONObject.put("radarAxisGlyph", this.radarAxisGlyph.toJSONObject());
    localJSONObject.put("isFilled", this.isFilled);
    localJSONObject.put("showLine", this.showLine);
    localJSONObject.put("showMarker", this.showMarker);
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "RadarPlotGlyph";
  }
}